Skip to content

feat(cli): let every command be driven through run() hermetically - #191

Merged
pgermishuys merged 1 commit into
mainfrom
phase/cli-fs-seam
Sep 20, 2026
Merged

pgermishuys merged 1 commit into
mainfrom
phase/cli-fs-seam

Conversation

@pgermishuys

Copy link
Copy Markdown
Contributor

Part of #183 — task group 13. Prerequisite for populating the CLI bucket.

The problem

The CLI bucket could only cover validate, because run() threaded no dependencies to anything else. No other command could be exercised from the outside without reading the developer's real disk, home directory and environment.

Correcting the framing

The audit said "five commands have no seam". That was imprecise — each already had one, they were just different seams, and run() passed none of them along:

Command Seam it already had
validate, init fs
migrate fs (required; reached through init, so already covered)
prompt configLoader, cwd
runtime cwd, storeFactory, dbExists
eval env, runner, validator overrides
compose none — Bun.file, process.cwd(), homedir() directly

So the work was mostly plumbing what already existed, plus giving compose a seam.

Threading cwd was not enough

This is the part worth reviewing. Passing an injected cwd to prompt looked sufficient and was not: loadConfig() falls back to its own Bun-backed reader, so the command still read the real disk. weave prompt list against a virtual config listed the builtins and never saw it.

I caught this because a scenario I had written was passing while asserting only typeof exitCode === "number" — weak enough to pass trivially. A probe confirmed SEES_VIRTUAL_AGENT=false. toConfigFileReader() bridges a FileSystem into config discovery, which is what actually closes the gap, and the scenarios now assert what the commands print and write.

compose

It had no seam at all. Config discovery, the bootstrap copy and every file the adapter writes now go through fs — the adapter's existing injectable I/O hooks made the last part straightforward.

Its bootstrap write was also unchecked — await Bun.write(dest, text) with no error path, so a failed write was silent. It now reports failures, which needs a FileWriteError variant on CliError.

Review notes

  • Default behaviour is unchanged. Every new parameter is optional and falls back to what the command did before.
  • One scenario I wrote and then deleted: it asserted a home-directory config must not reach a project command. That contradicts Weave's three-layer merge — global is merged into project by design — and only passed because the test preload disables the global layer. Shipping it would have encoded the wrong semantics.
  • 8 CLI scenarios added; tests/ now covers prompt list, prompt inspect (found and not-found), runtime status, compose (success and unsupported adapter), and eval environment filtering.

Verification

  • bun test ./tests: 26 pass, 0 fail
  • bun run test: 6,107 across 194 files, 0 fail
  • bun run typecheck, bun run lint, bun run verify:test-coverage, bun run docs:check-links: pass

🤖 Generated with Claude Code

https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve

The CLI bucket could only cover `validate`, because `run()` threaded no
dependencies to the other commands. They could not be exercised from the
outside without reading the developer's real disk, home directory and
environment.

The audit's framing — "five commands have no seam" — was imprecise. Each
already had one; they were simply different, and `run()` passed none of
them along:

  validate, init   fs
  migrate          fs (required; reached through init)
  prompt           configLoader, cwd
  runtime          cwd, storeFactory, dbExists
  eval             env, runner, validator overrides
  compose          none — Bun.file, process.cwd(), homedir() directly

`run()` now passes its injected `fs` to `compose`, `prompt` and `runtime`
alongside `validate` and `init`, derives `cwd` from it for commands that
locate work by path, and threads an injected `env` to `eval`.

Threading `cwd` alone was not enough. `loadConfig()` falls back to its own
Bun-backed reader, so a command handed an injected `cwd` still read the
real disk — `weave prompt list` against a virtual config listed the
builtins and never saw it. `toConfigFileReader()` bridges a `FileSystem`
into config discovery, which is what actually closes the gap.

`compose` had no seam at all and gains one: config discovery, the
bootstrap copy and every file the adapter writes now go through `fs`.
Its bootstrap write was also unchecked (`await Bun.write(...)` with no
error path); it now reports failures, which needs a FileWriteError
variant on CliError.

Eight CLI scenarios cover the result, asserting what the commands print
and write rather than merely that they returned a number.

Refs #183 (task group 13)

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DisVZW27sd6Pe7uhbjXNve
Copilot AI lite review requested due to automatic review settings September 20, 2026 16:18
@coderabbitai

coderabbitai Bot commented Sep 20, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 42 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: f814abd1-7738-4d0f-93e9-e08011061ad3

📥 Commits

Reviewing files that changed from the base of the PR and between 37bb7ee and 1410ac0.

⛔ Files ignored due to path filters (4)
  • .codesight/CODESIGHT.md is excluded by !.codesight/**
  • .codesight/coverage.md is excluded by !.codesight/**
  • .codesight/graph.md is excluded by !.codesight/**
  • .codesight/libs.md is excluded by !.codesight/**
📒 Files selected for processing (8)
  • docs/testing-strategy.md
  • packages/cli/src/cli.ts
  • packages/cli/src/commands/compose.ts
  • packages/cli/src/commands/prompt.ts
  • packages/cli/src/commands/runtime.ts
  • packages/cli/src/errors.ts
  • packages/cli/src/fs/file-system.ts
  • tests/cli/command-seams.scenario.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pgermishuys
pgermishuys merged commit c4ccde3 into main Sep 20, 2026
7 checks passed
@pgermishuys
pgermishuys deleted the phase/cli-fs-seam branch September 20, 2026 16:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟡 Changes recommended

Several new injected-filesystem paths currently swallow or ignore filesystem errors (notably compose adapter hooks and runtime/db existence checks), which can mask real failures and break hermetic correctness guarantees.

Get a fresh assessment by requesting another Copilot review.

Review effort: Lite
Findings: 3 Medium severity

Open (3)
What changed in this PR

This PR (part of #183 / task group 13) makes the CLI “bucket” viable by ensuring every CLI command can be driven through run() with injected dependencies (virtual filesystem / environment), so scenarios can execute hermetically without touching the developer’s real disk, $HOME, or ambient env.

Changes:

  • Thread fs (and cwd/env where needed) from packages/cli/src/cli.ts::run() into prompt, runtime, eval, and compose.
  • Add a FileSystem → @weaveio/weave-config bridge (toConfigFileReader) so config discovery uses injected I/O rather than Bun’s real filesystem defaults.
  • Add new black-box CLI scenarios covering prompt, runtime, compose, and eval seams; update testing strategy docs accordingly.
File Description
tests/​cli/​command-seams.scenario.test.ts New hermetic scenarios asserting commands are drivable via run() against a virtual FS/env.
packages/​cli/​src/​fs/​file-system.ts Adds toConfigFileReader() bridge to feed injected FileSystem into config discovery.
packages/​cli/​src/​errors.ts Adds FileWriteError variant and formatting for compose/bootstrap write failures.
packages/​cli/​src/​commands/​runtime.ts Allows runtime DB lookup to use injected fs/cwd instead of always consulting real disk.
packages/​cli/​src/​commands/​prompt.ts Ensures prompt config discovery uses injected fs via toConfigFileReader (not just injected cwd).
packages/​cli/​src/​commands/​compose.ts Adds fs seam for config discovery/bootstrap/adapter writes; adds explicit write failure reporting.
packages/​cli/​src/​cli.ts Threads injected fs/cwd/env through run() into command handlers.
docs/​testing-strategy.md Updates audit wording and records the new CLI seam approach.
.codesight/​libs.md Auto-updated metadata reflecting new symbols/types.
.codesight/​graph.md Auto-updated import graph metadata.
.codesight/​coverage.md Auto-updated test file count metadata.
.codesight/​CODESIGHT.md Auto-updated aggregate metadata snapshot.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines 61 to 64
// Check whether destination already exists
const existsCheck = await Bun.file(
join(destDir, BOOTSTRAP_FILES[0]),
).exists();
const existsResult = await fs.exists(join(destDir, BOOTSTRAP_FILES[0]));
const existsCheck = existsResult.isOk() && existsResult.value;
if (existsCheck) {
Comment on lines +353 to 362
const fs = ctx.fs;
const checkExists =
ctx.dbExists ??
(fs
? async (path: string) => {
const result = await fs.exists(path);
return result.isOk() && result.value;
}
: defaultDbExists);
const exists = await checkExists(dbPath);
Comment on lines +313 to +316
exists: async (path) => {
const result = await fs.exists(path);
return result.isOk() && result.value;
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants